<?php if(!empty($list_topic)):?>
<div id="topic-container">
<?php foreach($list_topic as $k=>$v):?>
<div class="topic sd1">
<table style="width: 100%;">
	<tr class="even">
		<td rowspan="2" width="65">
    		<a href="<?php echo site_url('c=member&m=index&id='.$v->poster_id);?>">
    			<img class="avator1" height="60" src="http://www.gravatar.com/avatar/<?php echo md5($v->posteremail);?>?s=60&d=&r=X"/>
    		</a>
		</td>
		<td colspan="9">
    		<?php if(!empty($v->rposter_id)):?>
    		<a href="<?php echo site_url('c=member&m=index&id='.$v->rposter_id);?>">
				<img src="http://www.gravatar.com/avatar/<?php echo md5($v->rposteremail);?>?s=30&d=&r=X"/>
			</a>
    		<?php endif;?>
			<a class="btn-ajax c2" befordo="playpop_befor" 
				music_id="<?php echo $v->music_id;?>" 
				href="<?php echo site_url('c=topic&m=hit&id='.$v->id);?>">#<?php echo $v->music_name;?>#</a>
			<?php echo $v->cont;?>
		</td>
	</tr>
	
	<tr>
		<td class="fs2">
		    <span class="c4"><?php echo $v->postername;?></span>
		    <span class="c3"><?php echo mydate($v->atime);?></span>
		</td>
		<td width="40">
			<?php if(!$is_login || $v->poster_id == $loginer->id):?>
				<span class="c3">推荐</span>
			<?php else:?>
				<a class="wm-ajax"
                	wmtitle="新音乐"
                	wmw="520"
                	wmh="380"
					href="<?php echo site_url('c=topic&m=post&recmd=yes&to_id='.$v->poster_id.'&reason_id='.$v->id);?>">推荐</a>
			<?php endif;?>
		</td>
		<td width="40">
			<a class="btn-ajax" 
				befordo="play_befor"
				music_id="<?php echo $v->music_id;?>" 
				href="<?php echo site_url('c=topic&m=hit&id='.$v->id);?>">播放</a>
		</td>
		<td width="80">
			<span class="c3">点击数<?php echo $v->count_hit;?></span>
		</td>
		<?php if($is_login):?>
		<td width="40">
    		<?php if($is_login && $loginer->id == $v->poster_id):?>
	    		<a class="btn-ajax-confirm" msg="Sure 不   ？" afterdo="topic_del_after"
	    			href="<?php echo site_url('c=topic&m=del&id='.$v->id);?>">删除</a>
	    	<?php else:?>
	    		<span class="c3">删除</span>
    		<?php endif;?>
    	</td>
    	<?php endif;?>
		<td width="70">
			<a class="btn-ajax-load btn-comment" alc="#panel-comment-<?php echo $v->id;?>" 
				befordo="befor_comment_do"
				href="<?php echo site_url('c=topic&m=reply&tid='.$v->id);?>">评论<span class="c3"><?php echo $v->count_reply;?></span></a>
		</td>
		<td width="80">
			<?php if($v->favo_status == 'normal'):?>
        		<a class="btn-ajax" 
            		href="<?php echo site_url('c=topic&m=favo&id='.$v->id);?>"
            		afterdo="favo_after_do"
            	>
        			<span class="favo-title">收藏</span> <span class="favo-count c3"><?php echo $v->count_favo;?></span>
        		</a>
			<?php elseif($v->favo_status == 'unfavo'):?>
        		<span class="c3" > 收藏<?php echo $v->count_favo;?> </span>
			<?php elseif($v->favo_status == 'favoed'):?>
        		<a class="btn-ajax" 
            		href="<?php echo site_url('c=topic&m=favo&id='.$v->id);?>"
            		afterdo="favo_after_do"
            	>
        			<span class="favo-title">取消收藏</span> 
        			<span class="favo-count c3"><?php echo $v->count_favo;?></span>
        		</a>
			<?php endif;?>
		</td>
		<td width="70">
			<a class="btn-ajax" 
				afterdo="dig_after_do"
				href="<?php echo site_url('c=topic&m=dig&type=good&id='.$v->id);?>">
				喜爱<span class="c3 dig-count"><?php echo $v->count_good_dig;?></span>
			</a>
		</td>
		<?php if($is_login):?>
		<td width="70">
					<a class="wm-ajax"
                    	wmtitle="转发"
                    	wmw="520"
                    	wmh="200"
						href="<?php echo site_url('c=topic&m=forward&rid='.$v->id);?>">
							转发<span class="c3"><?php echo $v->count_forward;?></span>						
						</a>
		</td>
		<?php endif;?>
	</tr>
</table>
<div id="panel-comment-<?php echo $v->id;?>" class="panel-comment"></div>
</div>
<?php endforeach;;?>


<script>

function befor_comment_do($elt){
	$elt.parents('.topic').siblings().find('..panel-comment .panel1').remove();
	if($elt.parents('.topic').find('..panel-comment .panel1').size()>0){
		$elt.parents('.topic').find('..panel-comment .panel1').remove();
		return false;
	}else{
		return true;
	}
}

function dig_after_do(msg,$elt){
	if(msg.status == 'succ'){
		$elt.empty().html(msg.data.count);
		return false;
	}
	
	return true;
	
}

function favo_after_do(msg,$elt){
	if(msg.status == 'succ'){
		$elt.find('.favo-count').empty().html(msg.data.count_favo);
		$elt.find('.favo-title').empty().html(msg.msg);
		return false;
	}
	
	return true;
}

//删除主题后的处理函数
function topic_del_after(msg,$elt){
	if(msg.status == 'succ'){
		$elt.parents('.topic').remove();
	}
	return false;
}

//收藏后操作
function favo_after_do(msg,$elt){
	if(msg.status == 'succ'){
		$elt.find('.favo-count').empty().html(msg.data.count_favo);
		$elt.find('.favo-title').empty().html(msg.msg);
		return false;
	}
	
	return true;
}

//喜欢后操作
function dig_after_do(msg,$elt){
	if(msg.status == 'succ'){
		$elt.find('.dig-count').text(msg.data.count);
		return false;
	}
	
	return true;
}

//播放前处理
function play_befor($elt){

	$('#music-media').remove();
	if($('#music-media') && $elt.attr('play') == '1'){
		$elt.attr('play','0');
		$elt.text('播放');
		return;
	}
	
	var music_id = $elt.attr('music_id');
	$('#topic-container').find('.btn-play').text('播放');
	
	$elt.text('暂停');
	$elt.attr('play','1');

	var media = '';
	media += '<div id="music-media"><embed height="33" width="257"';
	media += ' src="http://img.xiami.com/widget/0_'+music_id+'_/singlePlayer.swf"';
	media += ' menu="false" wmode="transparent" quality="high" ';
	media += ' pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"';
	media += ' type="application/x-shockwave-flash"></embed></div>';
	$('body').append(media);

	return true;
}

//弹出播放前处理
function playpop_befor($elt){
	var music_id = $elt.attr('music_id');
	playpop(music_id);
	return true;
}


</script>

</div>
<?php else:?>
暂无数据！
<?php endif;?>

